/**
 * Action
 * @author helio
 */
if(!SALE.Action) SALE.Action = {}

SALE.Action = {
	/**
	 * 用户登录
	 */
	loginAction : function(callback, submitForm) {
		if(SALE.App.loginType === "remote") {
			
			submitForm.doAction('submit', {
				url: SALE.App.configInfo.url + 'authz.php?action=login',
				method: 'post',
				
				success: function(form, action){ 
					Ext.MessageBox.hide();
					SALE.App.userInfo = action.result.user;
					//SALE.App.daoFactory = new SALE.dao.RemoteDaoFactory();
					SALE.App.initialize();
					
					callback();
		        },
				failure: function(form, action){  
					Ext.MessageBox.hide(); 
					if(action.result) {
						SALE.App.userInfo = action.result;
					} else {
						SALE.App.userInfo = {message: "服务器URL设置不正确，请及时与开发商联系。"};
					}
					
					SALE.Utils.showMessageBox(SALE.App.userInfo.message,"登录失败");
		        }
			});
		} else {
			SALE.App.daoFactory = new SALE.dao.LocalDaoFactory();
			var personnelDao = SALE.App.daoFactory.getPersonnelDao();
			
			var loginJson = submitForm.getValues();			
			SALE.App.userInfo = personnelDao.searchUserLoginJson(loginJson.loginid,loginJson.password);

			if(SALE.App.userInfo.success) {
				SALE.App.initialize();	
			} else {
				callback();
			}			
		}
	},
	
	logoutAction : function(callback) {
		if(SALE.App.loginType === "remote") {			
			Ext.Ajax.request({   
				url: SALE.App.configInfo.url + 'authz.php?action=logout',
	            success: function(response, options) { 
					this.userInfo = null;
					callback();
	            }   
	        });
		} else {
			this.userInfo = null;
			callback();	
		}
	},
	
	urlSettingAction : function(callback, urlStr) {
		
		LocalXMLFileUtil.configFileUtil.saveUrl(urlStr);
		
		Ext.MessageBox.show({
           	title: '设置成功',
           	msg: '服务器URL设置成功！！！',
          	buttons: Ext.MessageBox.OK,
          	fn: callback,
           	icon: Ext.MessageBox.INFO
       	});
	},
	
	passwordModifyAction : function(callback, password) {
		
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/password_modify.php',
            	params:{'param':Ext.encode(password)},
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	Ext.MessageBox.show({
                           	title: '修改成功',
                           	msg: '用户密码修改成功！！！',
                          	buttons: Ext.MessageBox.OK,
                          	fn: callback,
                           	icon: Ext.MessageBox.INFO
                       	});
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
		}
	},
	
	codeGenerator : function(callback,type) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'common/getcode.php',
            	params:{'param':Ext.encode({'type':type})},
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson.code); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			callback(SALE.Utils.createBillCode("XS"));
		}
	},
	
	getRealtimeInfo : function(callback) {
		if(SALE.App.loginType === "remote") {
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/realtime_info_list.php',                    
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson.details); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
		} else {
			
			var details = [];
			var results;
			/*var results = SALE.App.daoFactory.getSaleBillDao().searchSaleBillsArray({status:"0"});
			for(var i = 0 ; i < results.length; i++) {
				details.push({
					code:results[i].code,
					content:results[i].client,
					date:results[i].dispatch_date,
					status:"销售单 — 未确认",
					comment:""
				});	
			}
			
			//results = SALE.App.daoFactory.getPurchaseOrderDao().searchPurchaseOrdersArray({status:"0"});
			for(var i = 0 ; i < results.length; i++) {
				details.push({
					code:results[i].code,
					content:results[i].manufacturer,
					date:results[i].purchase_date,
					status:"订货单 — 未确认",
					comment:""
				});	
			}*/
			
			results = SALE.App.daoFactory.getStockDao().searchWarnningStocksJson({});
			for(var i = 0 ; i < results.length; i++) {
				
				var result = results[i];
				
				var number = result.number;
				var unumber = result.upper_limit;
				var lnumber = !result.lower_limit ? 0 : result.lower_limit;
				
				var comment = result.status == 1 ? "库存不足" : "库存挤压";
				var detail = result.sname + "库存量为：" + number + "<br/>";
				detail += result.status == 1 ? "最少库存量：" + lnumber : "最大库存量：" + unumber;
				
				details.push({
					code:results[i].pcode,
					content: results[i].pname,
					date:new Date(),
					status:"库存警报",
					comment:comment,
					detail: detail
				});	
			}
			
			callback(details);
		}
	},
	
	getBankAccountDetailsJson : function(callback) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/bank_account_list.php',                    
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var detailsJson = SALE.App.daoFactory.getBankAccountDao().buildBankAccountsJson();
			
			callback(detailsJson);
		}
	},
	
	searchBankAccountJson : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/bank_account_search_by_id.php',  
				params:{'param':Ext.encode({id:id})},                  
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson.account); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var resultJson = SALE.App.daoFactory.getBankAccountDao().searchBankAccountJsonByID(id);
			
			callback(resultJson);
		}
	},
	
	searchDefaultBankAccountJson : function(callback, createData, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'FindCategoryByCode.aspx',  
				params:{'param':Ext.encode({id:id})},                  
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                        Ext.Msg.alert('失败',responseJson.message);       
                    }   
                }   
            });
			
		} else {
			
			var resultJson = SALE.App.daoFactory.getBankAccountDao().searchDefaultBankAccountJson();
			
			if(resultJson) {
				createData.details[0].acode = resultJson.code;
				createData.details[0].aname = resultJson.name;
			}
			
			callback(createData, task);
		}
	},
	
	saveBankAccountInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/bank_account_edit.php',
				params:{'param':Ext.encode(formDataJson),'task':task},                 
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	formDataJson['id'] = responseJson.id;
                    	callback();  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			if(task == "new") {
				SALE.App.daoFactory.getBankAccountDao().insertBankAccountInfo(formDataJson);
			} else if(task == "modify") {
				SALE.App.daoFactory.getBankAccountDao().modifyBankAccountInfo(formDataJson);
			}
			
			callback();
		}
	},
	
	deleteBankAccountInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/bank_account_delete.php',
				params:{'param':Ext.encode(codeArray)},                   
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');
                    }   
                }   
            });
			
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				SALE.App.daoFactory.getBankAccountDao().deleteBankAccountInfo(id);
			}
			SALE.App.daoFactory.getBankAccountDao().saveDoc();
			
			callback();
		}
	},
	
	getCategoriesDetailsJson : function(callback) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/category_list.php',                    
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);        
                    }   
                }   
            });
			
		} else {
			
			var detailsJson = SALE.App.daoFactory.getCategoriesDao().buildCategoriesJson();
			
			callback(detailsJson);
		}
	},
	
	searchCategoryJson : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/category_search_by_id.php',  
				params:{'param':Ext.encode({id:id})},                  
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson.category); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);  
                    }   
                }   
            });
			
		} else {
			
			var resultJson = SALE.App.daoFactory.getCategoriesDao().searchCategoryJsonByID(id);
			
			callback(resultJson);
		}
	},
	
	saveCategoryInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/category_edit.php',
				params:{'param':Ext.encode(formDataJson),'task':task},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){ 
						formDataJson['id'] = responseJson.id;
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);         
                    }   
                }   
            });
			
		} else {
			
			if(task == "new") {
				SALE.App.daoFactory.getCategoriesDao().insertCategoryInfo(formDataJson);
			} else if(task == "modify") {
				SALE.App.daoFactory.getCategoriesDao().modifyCategoryInfo(formDataJson);
			}
			
			callback();
		}
	},
	
	deleteCategoriesInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id = recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/category_delete.php',
				params:{'param':Ext.encode(codeArray)},                   
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');
                    }   
                }   
            });
			
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id = recordList[i].get("id");
				SALE.App.daoFactory.getCategoriesDao().deleteCategoryInfo(id);
			}
			SALE.App.daoFactory.getCategoriesDao().saveCategoriesDoc();
			
			callback();
		}
	},
	
	getClassificationsDetailsJson : function(callback) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/classification_list.php',                    
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var detailsJson = SALE.App.daoFactory.getClassificationsDao().buildClassificationsJson();
			
			callback(detailsJson);
		}
	},
	
	searchClassificationJson : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/classification_search_by_id.php',  
				params:{'param':Ext.encode({id:id})},                  
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson.classification); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var resultJson = SALE.App.daoFactory.getClassificationsDao().searchClassificationJsonByID(id);
			
			callback(resultJson);
		}
	},
	
	saveClassificationInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/classification_edit.php',
				params:{'param':Ext.encode(formDataJson),'task':task},                 
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){ 
						formDataJson['id'] = responseJson.id;
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			if(task == "new") {
				SALE.App.daoFactory.getClassificationsDao().insertClassificationInfo(formDataJson);
			} else if(task == "modify") {
				SALE.App.daoFactory.getClassificationsDao().modifyClassificationInfo(formDataJson);
			}
			
			callback();
		}
	},
	
	deleteClassificationsInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id = recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/classification_delete.php',
				params:{'param':Ext.encode(codeArray)},                   
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');
                    }   
                }   
            });
			
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id = recordList[i].get("id");
				SALE.App.daoFactory.getClassificationsDao().deleteClassificationInfo(id);
			}
			SALE.App.daoFactory.getClassificationsDao().saveDoc();
			
			callback();
		}
	},
	
	
	getManufacturersListJson : function(callback, condition) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/manufacturer_list.php',  
            	params:{'param':Ext.encode(condition)},
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var detailsJson = SALE.App.daoFactory.getManufacturerDao().buildManufacturersJson();
			
			callback(detailsJson);
		}
	},
	
	searchManufacturerJson : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/manufacturer_search_by_id.php',  
				params:{'param':Ext.encode({id:id})},                  
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson.manufacturer); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var resultJson = SALE.App.daoFactory.getManufacturerDao().searchManufacturerJsonByID(id);
			
			callback(resultJson);
		}
	},
	
	saveManufacturerInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/manufacturer_edit.php',
				params:{'param':Ext.encode(formDataJson),'task':task},                 
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	formDataJson['id'] = responseJson.id;
                    	callback();  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			if(task == "new") {
				SALE.App.daoFactory.getManufacturerDao().insertManufacturerInfo(formDataJson);
			} else if(task == "modify") {
				SALE.App.daoFactory.getManufacturerDao().modifyManufacturerInfo(formDataJson);
			}
			
			callback();
		}
	},
	
	deleteManufacturersInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/manufacturer_delete.php',
				params:{'param':Ext.encode(codeArray)},                   
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');
                    }   
                }   
            });
			
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				SALE.App.daoFactory.getManufacturerDao().deleteManufacturerInfo(id);
			}
			SALE.App.daoFactory.getManufacturerDao().saveManufacturerDoc();
			
			callback();
		}
	},
	
	
	getClientsDetailsJson : function(callback, condition) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/client_list.php',
            	params:{'param':Ext.encode(condition)},
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);         
                    }   
                }   
            });
			
		} else {
			
			var detailsJson = SALE.App.daoFactory.getClientsDao().buildClientsJson();
			
			callback(detailsJson);
		}
	},
	
	searchClientJson : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/client_search_by_id.php',  
				params:{'param':Ext.encode({id:id})},                  
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson.client); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);        
                    }   
                }   
            });
			
		} else {
			
			var resultJson = SALE.App.daoFactory.getClientsDao().searchClientJsonByID(id);
			
			callback(resultJson);
		}
	},
	
	saveClientInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/client_edit.php',
				params:{'param':Ext.encode(formDataJson),'task':task},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	formDataJson['id'] = responseJson.id;
                    	callback();  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);          
                    }   
                }   
            });
			
		} else {
			
			if(task == "new") {
				SALE.App.daoFactory.getClientsDao().insertClientInfo(formDataJson);
			} else if(task == "modify") {
				SALE.App.daoFactory.getClientsDao().modifyClientInfo(formDataJson);
			}
			
			callback();
		}
	},
	
	deleteClientsInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/client_delete.php',
				params:{'param':Ext.encode(codeArray)},                   
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');      
                    }   
                }   
            });
			
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				SALE.App.daoFactory.getClientsDao().deleteClientInfo(id);
			}
			SALE.App.daoFactory.getClientsDao().saveClientDoc();
			
			callback();
		}
	},
	
	
	getStoragesDetailsJson : function(callback) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/storage_list.php',                    
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);       
                    }   
                }   
            });
			
		} else {
			
			var detailsJson = SALE.App.daoFactory.getStoragesDao().buildStoragesJson();
			
			callback(detailsJson);
		}
	},
	
	searchStorageJson : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/storage_search_by_id.php',  
				params:{'param':Ext.encode({id:id})},                  
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson.storage); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);     
                    }   
                }   
            });
			
		} else {
			
			var resultJson = SALE.App.daoFactory.getStoragesDao().searchStorageJsonByID(id);
			
			callback(resultJson);
		}
	},
	
	saveStorageInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/storage_edit.php',
				params:{'param':Ext.encode(formDataJson),'task':task},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	formDataJson['id'] = responseJson.id;
                    	callback();  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);      
                    }   
                }   
            });
			
		} else {
			
			if(task == "new") {
				SALE.App.daoFactory.getStoragesDao().insertStorageInfo(formDataJson);
			} else if(task == "modify") {
				SALE.App.daoFactory.getStoragesDao().modifyStorageInfo(formDataJson);
			}
			
			callback();
		}
	},
	
	deleteStoragesInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/storage_delete.php',
				params:{'param':Ext.encode(codeArray)},                   
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');  
                    }   
                }   
            });
			
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				SALE.App.daoFactory.getStoragesDao().deleteStorageInfo(id);
			}
			SALE.App.daoFactory.getStoragesDao().saveStorageDoc();
			
			callback();
		}
	},
	
	
	getUsersDetailsJson : function(callback) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/user_list.php',                    
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);					                                                             
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);       
                    }   
                }   
            });
			
		} else {
			
			var detailsJson = SALE.App.daoFactory.getPersonnelDao().buildUsersJson();
			
			callback(detailsJson);
		}
	},
	
	searchUserJson : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/user_search_by_id.php',  
				params:{'param':Ext.encode({id:id})},                  
                success: function(response, options) {
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson.user); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);       
                    }   
                }   
            });
			
		} else {
			
			var resultJson = SALE.App.daoFactory.getPersonnelDao().searchUserJsonByID(id);
			
			callback(resultJson);
		}
	},
	
	saveUserInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/user_edit.php',
				params:{'param':Ext.encode(formDataJson),'task':task},                 
                success: function(response, options) {
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	formDataJson['id'] = responseJson.id;
                    	callback(); 
                    } else {
                    	SALE.Utils.showMessageBox(responseJson.message, '添加失败');
                    }   
                }   
            });
			
		} else {
			
			if(task == "new") {
				SALE.App.daoFactory.getPersonnelDao().insertUserInfo(formDataJson);
			} else if(task == "modify") {
				SALE.App.daoFactory.getPersonnelDao().modifyUserInfo(formDataJson);
			}
			
			callback();
		}
	},
	
	deleteUsersInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/user_delete.php',
				params:{'param':Ext.encode(codeArray)},                   
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');
                    }   
                }   
            });
			
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				SALE.App.daoFactory.getPersonnelDao().deleteUserInfo(id);
			}
			SALE.App.daoFactory.getPersonnelDao().saveUserDoc();
			
			callback();
		}
	},
	
	getProductsSaleListJson: function(callback,condition) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/product_list.php',
            	params:{'action':'querystocks','param':Ext.encode(condition)},
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);       
                    }   
                }   
            });
			
		} else {
			
			var detailsJson = SALE.App.daoFactory.getProductsDao().buildProductsJson();
			
			callback(detailsJson);
		}
	},
	
	getProductsListJson : function(callback, condition) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/product_list.php', 
            	params:{'action':'query','param':Ext.encode(condition)},
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);       
                    }   
                }   
            });
			
		} else {
			
			var detailsJson = SALE.App.daoFactory.getProductsDao().buildProductsJson();
			
			callback(detailsJson);
		}
	},
	
	/*
	searchProductsByCondition : function(callback, condition) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/product_list_condition.php',  
				params:{'param':Ext.encode(condition)},                  
                success: function(response, options) {   
                       
					var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);       
                    }
                }   
            });
			
		} else {
			
			var resultJson = SALE.App.daoFactory.getProductsDao().searchProductJsonByID(id);
			
			callback(resultJson);
		}
	},*/
	
	searchProductJson : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/product_search_by_id.php',  
				params:{'param':Ext.encode({id:id})},                  
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson.product); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);       
                    }   
                }   
            });
			
		} else {
			
			var resultJson = SALE.App.daoFactory.getProductsDao().searchProductJsonByID(id);
			
			callback(resultJson);
		}
	},
	
	saveProductInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/product_edit.php',
				params:{'param':Ext.encode(formDataJson),'task':task},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	formDataJson['id'] = responseJson.id;
                    	callback();  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			if(task == "new") {
				SALE.App.daoFactory.getProductsDao().insertProductInfo(formDataJson);
			} else if(task == "modify") {
				SALE.App.daoFactory.getProductsDao().modifyProductInfo(formDataJson);
			}
			
			callback();
		}
	},
	
	saveAllProductsInfo : function(callback, products) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/product_list_save.php',
				params:{'param':Ext.encode(products)},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){  
                    	callback();  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			for(var i = 0; i < products.length; i++) {
				var product = products[i];
				
				SALE.App.daoFactory.getProductsDao().insertProductInfo(product);
			}
			
			callback({success:true, message: "批量添加商品信息成功。"});
		}
	},
	
	deleteProductsInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/product_delete.php',
				params:{'param':Ext.encode(codeArray)},                   
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');
                    }   
                }   
            });
			
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				SALE.App.daoFactory.getProductsDao().deleteProductInfo(id);
			}
			SALE.App.daoFactory.getProductsDao().saveProductsDoc();
			
			callback();
		}
	},
	
	checkStocksJson : function(callback, condition) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/stocks_check_list.php', 
            	params:{'param':Ext.encode(condition)},
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var detailsJson = SALE.App.daoFactory.getStockDao().searchStockByCondition(condition);
			
			callback(detailsJson);
		}
	},
	
	insertProductStocks : function(callback,record) {
		
		if(SALE.App.loginType === "remote") {
			var recordList = [record];			
			Ext.Ajax.request({				
            	url: SALE.App.configInfo.url + 'operate/stocks_list_save.php',
            	params:{'param':Ext.encode(recordList)},
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var isAdded = SALE.App.daoFactory.getStockDao().searchStockByCode(record.sname, record.pcode);
			
			if(!isAdded) {
				SALE.App.daoFactory.getStockDao().insertStockInfo(record);
				callback({success:true, message: "新加库存数量成功。"});
			} else {
				SALE.App.daoFactory.getStockDao().addStock(record);
				callback({success:true, message: "库存数量增加成功。"});
			}
		}
	},
	
	insertAllProductStocks : function(callback,recordList) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
				url: SALE.App.configInfo.url + 'operate/stocks_list_save.php',
            	params:{'param':Ext.encode(recordList)},
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			for (var i = 0; i < recordList.length; i++) {
				var record = recordList[i];
				
				var isAdded = SALE.App.daoFactory.getStockDao().searchStockByCode(record.sname, record.pcode);				
				if (isAdded) {
					SALE.App.daoFactory.getStockDao().addStock(record);	
				} else {
					SALE.App.daoFactory.getStockDao().insertStockInfo(record);
				}
			}
			
			callback({success:true, message: "批量添加库存信息成功。"});
		}
	},
	
	modifyProductStocks : function(callback,record) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/stocks_edit.php',                    
            	params:{'param':Ext.encode(record)},
            	success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var detailsJson = SALE.App.daoFactory.getStockDao().modifyStockInfo(record);
			
			callback();
		}
	},
	
	deleteProductStocks : function(callback,recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/stocks_delete.php',
				params:{'param':Ext.encode(codeArray)},                   
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');
                    }   
                }   
            });
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				SALE.App.daoFactory.getStockDao().deleteStockInfo(id);
			}
			SALE.App.daoFactory.getStockDao().saveStockDoc();
						
			callback();
		}
	},
	
	getDeptsDetailsJson : function(callback) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/department_list.php',                    
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);       
                    }   
                }   
            });
			
		} else {
			
			var detailsJson = SALE.App.daoFactory.getCompanyDeptDao().buildDeptsJson();
			
			callback(detailsJson);
		}
	},
	
	searchDeptJson : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/department_search_by_id.php',  
				params:{'param':Ext.encode({id:id})},                  
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson.dept); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var resultJson = SALE.App.daoFactory.getCompanyDeptDao().searchDeptJsonByID(id);
			
			callback(resultJson);
		}
	},
	
	saveDeptInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/department_edit.php',
				params:{'param':Ext.encode(formDataJson),'task': task},                 
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	formDataJson['id'] = responseJson.id;
                    	callback();  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			if(task == "new") {
				SALE.App.daoFactory.getCompanyDeptDao().insertDeptInfo(formDataJson);
			} else if(task == "modify") {
				SALE.App.daoFactory.getCompanyDeptDao().modifyDeptInfo(formDataJson);
			}
			
			callback();
		}
	},
	
	deleteDeptsInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/department_delete.php',
				params:{'param':Ext.encode(codeArray)},                   
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');
                    }   
                }   
            });
			
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				SALE.App.daoFactory.getCompanyDeptDao().deleteDeptInfo(id);
			}
			SALE.App.daoFactory.getCompanyDeptDao().saveCompanyDoc();
			
			callback();
		}
	},
	
	saveTransferBillInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/transfer_edit.php',
				params:{'param':Ext.encode(formDataJson),'task':task},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	if(responseJson.id) { 
                    		callback(responseJson.id); 
                    	} else {
                    		callback(responseJson); 
                    	}
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			if(task == "new") {
				SALE.App.daoFactory.getTransferBillDao().insertBillInfo(formDataJson);
			} else if(task == "modify") {
				SALE.App.daoFactory.getTransferBillDao().modifyBillInfo(formDataJson);
			} else if(task == "confirm") {
				for(var i = 0; i < formDataJson.length; i++){
					var record = recordList[i];
					SALE.App.daoFactory.getTransferBillDao().modifyBillInfo(record);
					result = {success: true, message: "调拨单确认成功！！！"}
				}
			}
			
			if(callback) callback(result);
		}
	},
	
	searchProductsTransferBill : function(callback, condition) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/transfer_search.php',
				params:{'param':Ext.encode(condition)},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	callback(responseJson.bills);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var results = SALE.App.daoFactory.getTransferBillDao().searchTransferBillsArray(condition);
			
			callback(results);
		}
	},
	
	deleteTransferBillInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id = recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/transfer_delete.php',
				params:{'param':Ext.encode(codeArray)},                   
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');
                    }   
                }   
            });
			
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id = recordList[i].get("id");
				SALE.App.daoFactory.getTransferBillDao().deleteBillInfo(id);
			}
			SALE.App.daoFactory.getTransferBillDao().saveBillDoc();
			
			callback();
		}
	},
	
	searchProductsTransferBillByID : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/transfer_search_by_id.php',
				params:{'param':Ext.encode({id:id})},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){ 
                    	callback(responseJson.bill);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var result = SALE.App.daoFactory.getTransferBillDao().searchTransferBillJson(id);
			
			callback(result);
		}
	},
	
	getSaleBillInitData: function(callback) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'common/initdata.php',
            	params:{action:'salebill'},
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			callback(SALE.Utils.createBillCode("XS"));
		}
	},
	
	saveSaleBillInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_edit.php',
				params:{'param':Ext.encode(formDataJson),'task':task},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	if(responseJson.id) { 
                    		callback(responseJson.id); 
                    	} else {
                    		callback(responseJson); 
                    	}
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			var result;
			if(task == "new") {
				result = SALE.App.daoFactory.getSaleBillDao().insertBillInfo(formDataJson);
			} else if(task == "modify") {
				SALE.App.daoFactory.getSaleBillDao().modifyBillInfo(formDataJson);
			} else if(task == "confirm") {
				for(var i = 0; i < formDataJson.length; i++){
					var record = recordList[i];
					SALE.App.daoFactory.getSaleBillDao().modifyBillInfo(record);
					result = {success: true, message: "销售单确认成功！！！"}
				}
			}
			
			if(callback) callback(result);
		}
	},
	
	postingSaleBill : function(callback,id) {
		
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_posting_directly.php',
				params:{'param':Ext.encode({id:id})},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){ 
                    	callback(responseJson);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var result = SALE.App.daoFactory.getSaleBillDao().searchSaleBillJson(id);
			var details = result.details;
			for(var i = 0; i < details.length; i++) {
				var detail = details[i];
				var stock_out = {
					pcode : detail.pcode,
					pname : detail.pname,
					punit : detail.punit,
					sname : !result.storage ? "" : result.storage,
					number : "-" + detail.pnumber
				}
				SALE.App.daoFactory.getStockDao().addStock(stock_out);
				
				SALE.App.daoFactory.getSaleBillDao().modifyBillInfo({
					id: result.id,
					end_flag: "1"
				});
			}
			
			var accountData = {
				'code' : SALE.Utils.createBillCode("SK"),
				'entry_date' : new Date(),
				'client' : result["client"],
				'operator' : SALE.App.userInfo.name,
				'comment' : "根据销售单生成",
				'type' : "0",
				'total' : result.total,
				'details' : [{
					acode : "",
					aname : result.account,
					aamount : result.total,
					acomment: ""
				}]
			}
			
			if (!accountData.details[0].aname || accountData.details[0].aname == "") {
				var resultJson = SALE.App.daoFactory.getBankAccountDao().searchDefaultBankAccountJson();
				
				if (resultJson) {
					accountData.details[0].acode = resultJson.code;
					accountData.details[0].aname = resultJson.name;
				}
			}
			
			SALE.App.daoFactory.getPaymentDao().insertPaymentInfo(accountData);
			
			if(callback) callback(result);
		}
	},
	
	searchSaleBill : function(callback, condition) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_search.php',
				params:{'param':Ext.encode(condition)},                 
                success: function(response, options) {   
                    
					var responseJson = SALE.Utils.result.decode(response);                                                                
                    if(responseJson.success==true){
                    	callback(responseJson.bills);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			condition.end_flag = "1";
			
			var results = SALE.App.daoFactory.getSaleBillDao().searchSaleBillsArray(condition);
			
			callback(results);
		}
	},
	
	searchSaleBillByID : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_search_by_id.php',
				params:{'param':Ext.encode({id:id})},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){ 
                    	callback(responseJson.bill);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var result = SALE.App.daoFactory.getSaleBillDao().searchSaleBillJson(id);
			
			callback(result);
		}
	},
	
	getInitShippingData : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_search_by_id.php',
				params:{'param':Ext.encode({id:id})},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){ 
                    	var result = responseJson.bill;
                    	var initData = {products: result.details};
            			
            			for(var i = 0; i < initData.products.length; i++) {
            				var product = initData.products[i];
            				
            				product.bcode = result.code;
            				product.storage = result.storage;
            				
            				if(!product.snumber || product.snumber == "") {
            					product.snumber = 0;
            				}
            				
            				product.number = parseFloat(product.pnumber) - parseFloat(product.snumber);
            			}
            			
            			callback(initData);
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			var result = SALE.App.daoFactory.getSaleBillDao().searchSaleBillJson(id);
			
			var initData = {products: result.details};
			
			for(var i = 0; i < initData.products.length; i++) {
				var product = initData.products[i];
				
				product.bcode = result.code;
				product.storage = result.storage;
				
				if(!product.snumber || product.snumber == "") {
					product.snumber = 0;
				}
				
				product.number = parseFloat(product.pnumber) - parseFloat(product.snumber);
			}
			
			callback(initData);
		}
	},
	
	shippingSaleProducts : function(callback, products) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_delivery.php',
				params:{'param':Ext.encode(products)},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	callback(responseJson.bills);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
						
			for(var i = 0; i < products.length; i++) {
				var product = products[i];
				SALE.App.daoFactory.getSaleBillDao().modifyBillProductShippingNumber(product);
				
				var stock_out = {
					pcode : product.pcode,
					pname : product.pname,
					punit : product.punit,
					sname : !product.storage ? "" : product.storage,
					number : "-" + product.number
				}
				SALE.App.daoFactory.getStockDao().addStock(stock_out);
			}
			
			callback(products);
		}
	},
	
	saveSaleRefundBillInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/refund_action.php',
				params:{'param':Ext.encode(formDataJson),'action':task},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	if(responseJson.id) { 
                    		callback(responseJson.id); 
                    	} else {
                    		callback(responseJson); 
                    	}
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
		}
	},
	
	confirmSaleRefundBill : function(callback,id) {
		
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/refund_action.php',
				params:{'param':Ext.encode([{id:id}]),'action':'confirm'},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){ 
                    	callback(responseJson);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
		}
	},
	
	searchSaleRefundBill : function(callback, condition) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/refund_action.php',
				params:{'param':Ext.encode(condition), 'action': 'search'},                 
                success: function(response, options) {   
                    
					var responseJson = SALE.Utils.result.decode(response);                                                                
                    if(responseJson.success==true){
                    	callback(responseJson.bills);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
		}
	},
	
	searchSaleRefundBillByID : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/refund_action.php',
				params:{'action':'detail',id:id},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	callback(responseJson.bill);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var result = SALE.App.daoFactory.getSaleBillDao().searchSaleBillJson(id);
			
			callback(result);
		}
	},
	
	deleteSaleRefundBillInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id = recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/refund_action.php',
				params:{'param':Ext.encode(codeArray), 'action':'delete'},                   
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');
                    }   
                }   
            });
			
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id = recordList[i].get("id");
				SALE.App.daoFactory.getSaleBillDao().deleteBillInfo(id);
			}
			SALE.App.daoFactory.getSaleBillDao().saveBillDoc();
			
			callback();
		}
	},
	
	createCollectBill : function(callback, record, task){
		
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_to_collect_bill.php',  
				params:{'param':Ext.encode(record)},                  
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson.record,task); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {

			record['code'] = SALE.Utils.createBillCode("SK");
			record['entry_date'] = new Date();
			
			var resultJson = SALE.App.daoFactory.getBankAccountDao().searchDefaultBankAccountJson();
			
			if(resultJson) {
				record.details[0].acode = resultJson.code;
				record.details[0].aname = resultJson.name;
			}
			
			callback(record, task);
		}
	},
	
	deleteSaleBillInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id = recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_delete.php',
				params:{'param':Ext.encode(codeArray)},                   
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');
                    }   
                }   
            });
			
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id = recordList[i].get("id");
				SALE.App.daoFactory.getSaleBillDao().deleteBillInfo(id);
			}
			SALE.App.daoFactory.getSaleBillDao().saveBillDoc();
			
			callback();
		}
	},

	getPurchaseOrderInitData: function(callback) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'common/initdata.php',
            	params:{action:'purchaseorder'},
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			callback(SALE.Utils.createBillCode("XS"));
		}
	},
	
	savePurchaseOrderInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/purchase_edit.php',
				params:{'param':Ext.encode(formDataJson),'task':task},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	if(responseJson.id) { 
                    		callback(responseJson.id); 
                    	} else {
                    		callback(responseJson); 
                    	}
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			if(task == "new") {
				result = SALE.App.daoFactory.getPurchaseOrderDao().insertOrderInfo(formDataJson);
			} else if(task == "modify") {
				SALE.App.daoFactory.getPurchaseOrderDao().modifyOrderInfo(formDataJson);
			} else if(task == "confirm") {
				for(var i = 0; i < formDataJson.length; i++){
					var record = recordList[i];
					SALE.App.daoFactory.getPurchaseOrderDao().modifyOrderInfo(record);
					result = {success: true, message: "采购单确认成功！！！"}
				}
			}
			
			if(callback) callback(result);
		}
	},
	
	searchPurchaseOrder : function(callback, condition) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/purchase_search.php',
				params:{'param':Ext.encode(condition)},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	callback(responseJson.bills);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var results = SALE.App.daoFactory.getPurchaseOrderDao().searchPurchaseOrdersArray(condition);
			
			callback(results);
		}
	},
	
	searchPurchaseOrderByID : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/purchase_search_by_id.php',
				params:{'param':Ext.encode({id:id})},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){ 
                    	callback(responseJson.bill);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var result = SALE.App.daoFactory.getPurchaseOrderDao().searchPurchaseOrderJson(id);
			
			callback(result);
		}
	},
	
	createPaymentBill : function(callback, record, task){
		
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/purchase_to_payment_bill.php',  
				params:{'param':Ext.encode(record)},                  
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson.record,task); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {

			record['code'] = SALE.Utils.createBillCode("FK");
			record['entry_date'] = new Date();
			
			var resultJson = SALE.App.daoFactory.getBankAccountDao().searchDefaultBankAccountJson();
			
			if(resultJson) {
				record.details[0].acode = resultJson.code;
				record.details[0].aname = resultJson.name;
			}
			
			callback(record, task);
		}
	},
	
	deletePurchaseOrderInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id = recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/purchase_delete.php',
				params:{'param':Ext.encode(codeArray)},                   
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');
                    }   
                }   
            });
			
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id = recordList[i].get("id");
				SALE.App.daoFactory.getPurchaseOrderDao().deleteOrderInfo(id);
			}
			SALE.App.daoFactory.getPurchaseOrderDao().saveOrderDoc();
			
			callback();
		}
	},
	
	searchReceiveBillDataJson : function(callback, condition) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/storage_receiving_list.php',
				params:{'param':Ext.encode(condition)},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	callback(responseJson);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);      
                    }   
                }   
            });
			
		} else {
			
			var receivesJson = {receives:[]};
			
			var purchaseResults = SALE.App.daoFactory.getPurchaseOrderDao().searchPurchaseOrderDetailsArray(condition);
			for(var i = 0; i < purchaseResults.length; i++) {
				var purchase = purchaseResults[i];
				for(var j = 0; j < purchase.details.length; j++) {
					var detail = purchase.details[j];
					if(detail){
						var pnumber = detail.pnumber != null && detail.pnumber != "" ? parseFloat(detail.pnumber) : 0;
						var rnumber = detail.receive_number != null && detail.receive_number != "" ? parseFloat(detail.receive_number) : 0;
						var number = pnumber - rnumber;
						if(number > 0) {
							var receiveJson = {
								'index' : detail.index,
								'bcode' : purchase.code,
								'storage_in' : purchase.storage_in,
								'pcode' : detail.pcode, 
								'pname' : detail.pname, 
								'pnumber' : pnumber, 
								'punit' : detail.punit,
								'pamount' : detail.pamount, 
								'rnumber' : rnumber, 
								'number' : number,
								'type' : '1'
							};
							receivesJson.receives.push(receiveJson);
						}
						
					}					
				}
			}
			
			var transferResults = SALE.App.daoFactory.getTransferBillDao().searchTransferBillDetailsArray(condition);
			for(var i = 0; i < transferResults.length; i++) {
				var transfer = transferResults[i];
				for(var j = 0; j < transfer.details.length; j++) {
					var detail = transfer.details[j];
					if(detail){
						var pnumber = detail.pnumber != null && detail.pnumber != "" ? parseFloat(detail.pnumber) : 0;
						var rnumber = detail.receive_number != null && detail.receive_number != "" ? parseFloat(detail.receive_number) : 0;
						var number = pnumber - rnumber;
						if (number > 0) {
							var receiveJson = {
								'index' : detail.index,
								'bcode': transfer.code,
								'storage_in': transfer.storage_in,
								'storage_out': transfer.storage_out,
								'pcode': detail.pcode,
								'pname': detail.pname,
								'pnumber': pnumber,
								'punit': detail.punit,
								'pamount': detail.pamount,
								'rnumber': rnumber,
								'number': number,
								'type': '2'
							};
							receivesJson.receives.push(receiveJson);
						}
					}					
				}
			}
			
			callback(receivesJson);
		}
	},
	
	saveReceiveBillData : function(callback, recordJson) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/storage_receiving_edit.php',
				params:{'param':Ext.encode(recordJson)},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	var pnumber = recordJson.pnumber;
            			var rnumber = recordJson.rnumber ? recordJson.rnumber : 0;	
            			var number = recordJson.number;
            			
            			recordJson.rnumber = parseFloat(rnumber) + parseFloat(number);
            			recordJson.number = parseFloat(pnumber) - parseFloat(recordJson.rnumber);
            			
                    	callback(responseJson);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }
                }   
            });
			
		} else {
			
			if(recordJson.type == "1") {
				var stock = {
					pcode : recordJson.pcode,
					pname : recordJson.pname,
					punit : recordJson.punit,
					sname : recordJson.storage_in,
					number : recordJson.number
				}
				SALE.App.daoFactory.getStockDao().addStock(stock);
				
				SALE.App.daoFactory.getPurchaseOrderDao().modifyOrderProductReceiveNumber(recordJson);
				
				
				
			} else if(recordJson.type == "2"){
				var stock_out = {
					pcode : recordJson.pcode,
					pname : recordJson.pname,
					punit : recordJson.punit,
					sname : recordJson.storage_out,
					number : "-" + recordJson.number
				}
				SALE.App.daoFactory.getStockDao().addStock(stock_out);
				
				var stock_in = {
					pcode : recordJson.pcode,
					pname : recordJson.pname,
					punit : recordJson.punit,
					sname : recordJson.storage_in,
					number : recordJson.number
				}
				SALE.App.daoFactory.getStockDao().addStock(stock_in);
				
				SALE.App.daoFactory.getTransferBillDao().modifyBillProductReceiveNumber(recordJson);
			}
			
			
			var pnumber = recordJson.pnumber;
			var rnumber = recordJson.rnumber;			
			var number = recordJson.number;
			
			recordJson.rnumber = parseFloat(rnumber) + parseFloat(number);
			recordJson.number = parseFloat(pnumber) - parseFloat(recordJson.rnumber);
			
			callback({success: true, message: "商品入库成功！！！"});
		}
	},
	
	savePaymentInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/ledger_edit.php',
				params:{'param':Ext.encode(formDataJson),'task':task},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	if(responseJson.record) { 
                    		callback(responseJson.record); 
                    	} else {
                    		callback(responseJson); 
                    	}
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			if(task == "new") {
				SALE.App.daoFactory.getPaymentDao().insertPaymentInfo(formDataJson);
			} else if(task == "modify") {
				SALE.App.daoFactory.getPaymentDao().modifyPaymentInfo(formDataJson);
			} else if(task == "auto") {
				
				if (formDataJson.type == 0) {
					var updateJson = {
						id: formDataJson.sbid,
						payment_flag: 1
					};
					
					SALE.App.daoFactory.getSaleBillDao().modifyBillInfo(updateJson);
					formDataJson.sbid = null;
				}
				
				SALE.App.daoFactory.getPaymentDao().insertPaymentInfo(formDataJson);
			}
			
			if(callback) callback();
		}
	},
	
	searchPayment : function(callback, condition) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/ledger_search.php',
				params:{'param':Ext.encode(condition)},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	callback(responseJson.ledgers);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var results = SALE.App.daoFactory.getPaymentDao().searchPaymentsArray(condition);
			
			callback(results);
		}
	},
	
	searchGeneralLedger : function(callback, condition) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/ledger_search.php',
				params:{'param':Ext.encode(condition)},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	callback(responseJson);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var results = SALE.App.daoFactory.getPaymentDao().searchPaymentsArray(condition);
			
			callback(results);
		}
	},
	
	searchPaymentByID : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/ledger_search_by_id.php',
				params:{'param':Ext.encode({id:id})},                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){ 
                    	callback(responseJson.ledger);  
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);
                    }   
                }   
            });
			
		} else {
			
			var result = SALE.App.daoFactory.getPaymentDao().searchCollectBillJson(id);
			
			if(callback) callback(result);
		}
	},
	
	deletePaymentInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id = recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/ledger_delete.php',
				params:{'param':Ext.encode(codeArray)},                   
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');
                    }   
                }   
            });
			
		} else {
			
			for (var i = 0; i < recordList.length; i++) {
				var id = recordList[i].get("id");
				SALE.App.daoFactory.getPaymentDao().deletePaymentInfo(id);
			}
			SALE.App.daoFactory.getPaymentDao().savePaymentDoc();
			
			callback();
		}
	},
	
	searchSaleDailyStatus : function(callback, date) {
		
		if(!date) {
			date = new Date();
		}
		
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_itemize_daily.php',
            	params:{'param':Ext.encode({'date':Ext.util.Format.date(date,"Y-m-d")})},
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);        
                    }   
                }   
            });
			
		} else {
			
			var statusJson = SALE.App.daoFactory.getSaleBillDao().searchSaleDailyStatus(date);
			
			callback(statusJson);
		}
	},

	searchSaleRecentlyDateStatus : function(callback, initData) {
				
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_itemize_daily_recently.php',
            	params:{'param':Ext.encode({'date':Ext.util.Format.date(new Date(),"Y-m-d")})},
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	initData.data = responseJson.products;
                    	callback(initData); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);        
                    }   
                }   
            });
			
		} else {
			
			var data = SALE.App.daoFactory.getSaleBillDao().searchSaleRecentlyDateStatus();
			initData.data = data;
			
			callback(initData);
		}
	},

	searchProductRecentlyDateStatus : function(callback, initData, code) {
				
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_itemize_daily_recently.php',
            	params:{'param':Ext.encode({'date':Ext.util.Format.date(new Date(),"Y-m-d"),'code':code})},
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	initData.data = responseJson.products;
                    	callback(initData); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);        
                    }   
                }   
            });
			
		} else {
			
			var data = SALE.App.daoFactory.getSaleBillDao().searchProductRecentlyDateStatus(code);
			initData.data = data;
			
			callback(initData);
		}
	},
	
	searchSaleMonthlyStatus : function(callback, date) {
		
		if(!date) {
			date = new Date();
		}
		
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_itemize_monthly.php',
            	params:{'param':Ext.encode({'date':date})},
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);        
                    }   
                }   
            });
			
		} else {
			
			var statusJson = SALE.App.daoFactory.getSaleBillDao().searchSaleDailyStatus(date,true);
			
			callback(statusJson);
		}
	},
	
	searchSaleStatusTop : function(callback, date) {
		
		if(!date) {
			date = new Date();
		}
		
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_itemize_top.php',
            	params:{'param':Ext.encode({'date':date})},
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);        
                    }   
                }   
            });
			
		} else {
			
			var statusJson = SALE.App.daoFactory.getSaleBillDao().searchSaleDailyStatus(date,true);
			
			callback(statusJson);
		}
	},

	searchSaleRecentlyMonthStatus : function(callback, initData) {
				
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_itemize_monthly_recently.php',
            	params:{'param':Ext.encode({'date':Ext.util.Format.date(new Date(),"Y-m-d")})},
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	initData.data = responseJson.products;
                    	callback(initData); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);        
                    }   
                }   
            });
			
		} else {
			
			var data = SALE.App.daoFactory.getSaleBillDao().searchSaleRecentlyMonthStatus();
			initData.data = data;
			
			callback(initData);
		}
	},
	
	searchProductRecentlyMonthStatus : function(callback, initData, code) {
				
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/sale_itemize_monthly_recently.php',
            	params:{'param':Ext.encode({'date':Ext.util.Format.date(new Date(),"Y-m-d"),'code':code})},
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){
                    	initData.data = responseJson.products;
                    	callback(initData); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);        
                    }   
                }   
            });
			
		} else {
			
			var data = SALE.App.daoFactory.getSaleBillDao().searchProductRecentlyMonthStatus(code);
			initData.data = data;
			
			callback(initData);
		}
	},

	searchTrackRecordStocks : function(callback,query) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/track_record_stocks_list.php',  
            	params:{'param':Ext.encode({'date':query})},
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);        
                    }   
                }   
            });
			
		} else {
			
			//var detailsJson = SALE.App.daoFactory.getCategoriesDao().buildCategoriesJson();
			
			//callback(detailsJson);
		}
	},
	
	searchTrackRecordMoney : function(callback,query) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/track_record_money_list.php',  
            	params:{'param':Ext.encode({'date':query})},
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);        
                    }   
                }   
            });
			
		} else {
			
			//var detailsJson = SALE.App.daoFactory.getCategoriesDao().buildCategoriesJson();
			
			//callback(detailsJson);
		}
	},
	
	searchLedgerStatisticsData : function(callback,query) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'operate/ledger_statistics_search.php',  
            	params:{'param':Ext.encode(query)},
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);        
                    }   
                }   
            });
			
		} else {
			
			//var detailsJson = SALE.App.daoFactory.getCategoriesDao().buildCategoriesJson();
			
			//callback(detailsJson);
		}
	},
	
	userAuthzSave : function(callback,params) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'manage/user_authz_edit.php',  
            	params:{'param':Ext.encode(params)},
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);        
                    }   
                }   
            });
			
		} else {
			
			//var detailsJson = SALE.App.daoFactory.getCategoriesDao().buildCategoriesJson();
			
			//callback(detailsJson);
		}
	},
	
	getNewsListJson : function(callback) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'special/news_manage.php',
            	params:{action:'list'},
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);					                                                             
                    if(responseJson.success==true){   
                    	callback(responseJson); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);       
                    }   
                }   
            });
			
		} else {
			
			//var detailsJson = SALE.App.daoFactory.getPersonnelDao().buildUsersJson();
			
			//callback(detailsJson);
		}
	},
	
	getNewsDetailJson : function(callback, id) {
		if(SALE.App.loginType === "remote") {
			
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'public/news_select.php',  
				params:{'id':id, 'action': 'detail'},                  
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(responseJson.news); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);       
                    }   
                }   
            });
			
		} else {
			
			//var resultJson = SALE.App.daoFactory.getProductsDao().searchProductJsonByID(id);
			
			//callback(resultJson);
		}
	},
	
	saveNewInfo : function(callback, formDataJson, task) {
		if(SALE.App.loginType === "remote") {
			formDataJson['action'] = 'update';
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'special/news_manage.php',
				params: formDataJson,                 
                success: function(response, options) {   
                    
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                	if(responseJson.success==true){ 
						formDataJson['id'] = responseJson.id;
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message);         
                    }   
                }   
            });
			
		} else {
			
		}
	},
	
	deleteNewsInfo : function(callback, recordList) {
		if(SALE.App.loginType === "remote") {
			var codeArray = [];
			for (var i = 0; i < recordList.length; i++) {
				var id= recordList[i].get("id");
				codeArray.push({'id':id});
			}
			Ext.Ajax.request({   
            	url: SALE.App.configInfo.url + 'special/news_manage.php',
				params:{'param':Ext.encode(codeArray), 'action': 'delete'},                   
                success: function(response, options) {   
                       
                	var responseJson = SALE.Utils.result.decode(response);                                                                 
                    if(responseJson.success==true){   
                    	callback(); 
                    } else {   
                    	SALE.Utils.showMessageBox(responseJson.message, '删除失败');  
                    }   
                }   
            });
			
		} else {
			
			
		}
	}
}
